<template>
    <div id="dialogEdit" >
        <el-dialog :title="title"
                   @close="cancels"
                   :close-on-click-modal="false"
                   :show-close="false"
                   :visible.sync="dialogFormVisible">
            <div v-if="type==true">
                <el-form :model="form">
                    <el-form-item label="作用域：" label-width="115px">
                        <el-select :value="form.parentId" v-model="form.parentId"
                                    placeholder="请选择" size="small">
                            <el-option
                                    v-for="item in selectItem"
                                    :key="item.id"
                                    :label="item.codeDesc"
                                    :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item >
                        <span class="form-label">类型：</span>
                        <el-input class="formInput" v-model="form.codeKey" autocomplete="off"></el-input>
                        <span class="form-label" style="margin-left: 20%">类型描述：</span>
                        <el-input class="formInput" v-model="form.keyDesc" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item >
                        <span class="form-label">码值：</span>
                        <el-input class="formInput" v-model="form.codeValue" autocomplete="off"></el-input>
                        <span class="form-label" style="margin-left: 20%">码值描述：</span>
                        <el-input class="formInput" v-model="form.valueDesc" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div v-else>
                <el-form :model="form">
                    <el-form-item >
                        <span class="form-label">作用域：</span>
                        <el-input class="formInput" v-model="form.codeDesc" autocomplete="off"></el-input>
                        <span class="form-label">code：</span>
                        <el-input class="formInput" v-model="form.code" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-alert
                            title="code结构为：字母+四位数字"
                            type="info">
                    </el-alert>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancels">取 消</el-button>
                <el-button type="primary" @click="btnOk">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import Message from "../../../components/messages/index"
    export default {
        name:"CodeEdit",
        props: {
            dialogFormVisible:Boolean,
            data:null,
            title:{},
            type:null
        },
        data(){
            return{
                form:{},
                selectItem:[],
            }
        },
        methods:{
            isEmpty(obj){
                if(typeof obj=="undefined"||obj==null||obj===""){
                    return true;
                }else{
                    return false;
                }
            },
            cancels(){
                this.form={};
                this.selectItem={};
                this.$emit("cancel");
            },
            btnOk(){
                if(this.title==="新增码表值"){
                    if(this.isEmpty(this.form.parentId)){
                        Message.warning("作用域不为空！");
                        return;
                    }
                    this.$emit("btnAddOk",this.form);
                }else if(this.title==="新增作用域") {
                    this.$emit("btnAddOk",this.form);
                }else if(this.title==="修改码表值"){
                    this.$emit("btnUpdateOk",this.form);
                }
            }
        },
        watch:{
            data:function () {
                if(this.data){
                    if(this.data[0]){
                        this.form=this.data[0];
                    }
                    this.selectItem=this.data[1];
                }
            }
        },

    }
</script>

<style scoped>
    .formInput{
        width:150px;
        height: 20px;
        margin-left: 10px;
    }
    .form-label{
        font-size: 14px;
        display: inline-block;
        margin-left: 50px;
    }
</style>